import axios from 'axios'
import jsonp from 'common/jsonp.js'
import {commonParams, options} from './config.js'

// 对axios请求的原理一知半解，后面要加强练习
export function GetRanks() {

  const url = '/api/GetRank?_='+(new Date()).getTime()
  const data = {"req_0":{"module":"musicToplist.ToplistInfoServer","method":"GetAll","param":{}},"comm":{"g_tk":5381,"uin":1600086411,"format":"json","ct":23,"cv":0}}
  return axios.post(url,data).then((res) => {
    return Promise.resolve(res.data)
  })
}

export function GetRank() {
  const url = 'https://c.y.qq.com/v8/fcg-bin/fcg_myqq_toplist.fcg'
  const data = {
    g_tk: 1928093487,
    inCharset: 'utf-8',
    outCharset: 'utf-8',
    notice: 0,
    format: 'jsonp',
    uin: 0,
    needNewCode: 1,
    platform: 'h5'
  }
  return jsonp(url, data, options)
}

export function GetSongList(topid) {
  const url = 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_toplist_cp.fcg'
  const data = {
    g_tk: 1928093487,
    inCharset: 'utf-8',
    outCharset: 'utf-8',
    notice: 0,
    format: 'jsonp',
    topid: topid,
    needNewCode: 1,
    uin: 0,
    tpl: 3,
    page: 'detail',
    type: 'top',
    platform: 'h5'
  }
  return jsonp(url, data, options)
}